我们正在更新 Data API,以便与 YouTube 统计 Shorts 短视频观看次数的方式保持一致。
了解详情
实现:部分响应
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
以下示例展示了如何在 YouTube Data API (v3) 中检索部分 API 响应。
注意:该 API 的入门指南详细介绍了部分请求和响应。
v3 API 允许(实际上需要)检索部分资源,以便应用避免传输、解析和存储不需要的数据。这种方法还可确保 API 更高效地使用网络、CPU 和内存资源。
该 API 支持两个请求参数:part
和 fields
,可让您确定应包含在 API 响应中的资源属性。part
参数还用于标识应由用于插入或更新资源的 API 请求设置的属性。
请注意,如果更新请求未为之前具有值的资源属性指定值,则在满足以下条件时,系统会删除现有值:
示例
例如,假设您要更新下方所示的 video
资源。(请注意,以下所有属性都可以通过 API 更新,并且我们省略了与示例无关的资源属性。)
{
"snippet": {
"title": "Old video title",
"description": "Old video description",
"tags": ["keyword1","keyword2","keyword3"],
"categoryId: 22
},
"status": {
"privacyStatus": "private",
"publishAt": "2014-09-01T12:00:00.0Z",
"license": "youtube",
"embeddable": True,
"publicStatsViewable": True
}
}
您可以调用 videos.update
方法,并将 part
参数值设置为 snippet
。API 请求正文包含以下资源:
{
"snippet": {
"title": "New video title",
"tags": ["keyword1","keyword2","keyword3"],
"categoryId: 22
}
}
此请求会更新视频的标题、删除其说明,但不会更改其标签或类别 ID。由于请求未为 snippet.description
属性指定值,因此系统会删除视频的说明。
status
对象中的属性完全没有受到影响,因为 part
参数值未将 status
作为请求要更新的部分之一。事实上,如果 API 请求的正文包含 status
对象,则由于请求正文中包含意外部分,API 会返回 400 (Bad Request)
HTTP 响应。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-11-23。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2024-11-23。"],[[["The YouTube Data API (v3) requires retrieving partial resources to optimize data transfer, parsing, and storage."],["The `part` and `fields` parameters enable users to specify which resource properties to include in API responses."],["The `part` parameter also dictates which properties are set during resource insertion or update requests."],["Omitting a previously valued property in an update request, within the specified `part`, will delete that property's value if modifiable."],["Including unexpected parts in an update request's body, meaning a part not listed in the `part` parameter, will result in a `400 (Bad Request)` HTTP response."]]],["The YouTube Data API (v3) uses `part` and `fields` parameters to enable partial resource retrieval, improving efficiency by avoiding unnecessary data transfer. The `part` parameter identifies properties for retrieval and modification. When updating, omitting a previously valued property in the specified `part` results in its deletion. For example, updating a video resource's `snippet` part without including `description` deletes the description. Updating a property that is not in the part of the request being modified is not possible.\n"]]